const webpack = require('webpack');
const dotenv = require('dotenv');
const path = require('path');
const cyberConf = require('./cybercloud.config');

const dot = dotenv.config({ path: path.resolve('.cybercloud') });
module.exports = {
  configureWebpack(config) {
    config.plugins.push(
      new webpack.ProvidePlugin({
        cyber: [path.resolve(__dirname, './lib/cybercloud'), 'default'],
      }),
      new webpack.DefinePlugin({
        CYBER_ENV: JSON.stringify({ ...dot.parsed, ...cyberConf }),
      }),
    );
  },
  chainWebpack(config) {
    config.plugin('html').tap((args) => {
      args[0].title = config.title || '库位';
      return args;
    });
  },

  devServer: {
    proxy: {
      '/api': {
        target: 'http://localhost:8081/api',
        changeOrigin: true,
        pathRewrite: {'^/api': ''},
      }
    },
    headers: {
      'Access-Control-Allow-Origin': '*'
    },
  },
};
